package com.groupten.MyController;

import com.groupten.Entity.StudentEntity;
import com.groupten.Entity.TeacherEntity;
import com.groupten.Service.LoginService;
import com.groupten.ServiceImpl.StudentServiceImpl;
import com.groupten.ServiceImpl.TeacherServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("group10/hbjLogin")
public class HbjLoginController {

    @Autowired
    private LoginService loginService;
    @Autowired
    private TeacherServiceImpl teacherService;
    @Autowired
    private StudentServiceImpl studentService;

    @RequestMapping("encryptPassword")
    public Boolean encryptPassword(String number){
        TeacherEntity teacher = teacherService.selectByNumber(number);
        if (teacher != null){
            return loginService.encryptPasswordOfTeacher(number);
        }
        StudentEntity student = studentService.selectByNumber(number);
        if (student != null){
            return loginService.encryptPasswordOfStudent(number);
        }
        return false;
    }

    @RequestMapping("login")
    public String login(String number, String password){
        return loginService.login(number, password);
    }

    @RequestMapping("registerOfStudent")
    public String registerOfStudent(@RequestBody StudentEntity student){
        return loginService.registerOfStudent(student);
    }

    @RequestMapping("registerOfTeacher")
    public String registerOfTeacher(@RequestBody TeacherEntity teacher){
        return loginService.registerOfTeacher(teacher);
    }

}
